#pragma once

#include <sys/fcntl.h>
#include <cstdio>
#include <stdlib.h>

class NoCopy    // 子类继承 NoCopy 便不能使用拷贝构造和赋值拷贝
{
public:

    NoCopy(const NoCopy&) = delete;
    NoCopy& operator=(const NoCopy&) = delete;

    NoCopy() = default;
    ~NoCopy() = default;
};

enum ExitCode
{
    NORMAL = 0,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR,
    FORK_ERR,
    EPOLL_CREATE_ERR,
};

void setNonBlock(int fd)
{
    int n = fcntl(fd, F_GETFL);
    if (n < 0)
    {
        perror("fcntl get");
        exit(1);
    }

    n = fcntl(fd, F_SETFL, n | O_NONBLOCK);
    if (n < 0)
    {
        perror("fcntl set");
        exit(1);
    }
}